package com.anzia.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 *@ClassName Map_Demo
 *@Description
 *@Author Anzia.
 *@Date 2021/4/10 15:22
 *@Version 1.0
 **/
public class Map_Demo {
    public static void main(String[] args) {
        //创建集合
        HashMap<String, String> hashMap = new HashMap<>();

        //添加数据
        hashMap.put("cn","中国");
        hashMap.put("uk","英国");
        hashMap.put("usa","美国");

        System.out.println(hashMap.size());
        System.out.println(hashMap);

        //删除
        //hashMap.remove("usa");
        //System.out.println(hashMap);

        //遍历
        //使用keySet()遍历
        System.out.println("---------");
        Set<String> keySet = hashMap.keySet();
        for (String s : keySet) {
            System.out.println(s + " : " + hashMap.get(s));
        }
        //使用entrySet()方法
        System.out.println("---------");
        //Set<Map.Entry<String, String>> entrySet = hashMap.entrySet();
        for (Map.Entry<String, String> entry : hashMap.entrySet()) {
            System.out.println(entry.getKey() + " : " + entry.getValue());
        }

        //判断
        System.out.println("---------");
        System.out.println(hashMap.containsKey("cn"));
        System.out.println(hashMap.containsValue("泰国"));
        System.out.println(hashMap.isEmpty());
    }
}
